Using sockets to transfer files between client and server


代写完成–Java Socket 文件交换


Write two applications, a server and a client, that transfer files between each other using sockets.

The server application should:

  • Run continuously.

  • Use an Executor to manage a fixed thread-pool with 10 connections.

  • Following a request by a client, query the local folder serverFiles and return a list of the files found there to the same client.

  • Send a file from serverFiles to a client that requests it.

  • Read a file from a client and place it in the serverFiles folder.

  • Log every request by a client in a local file log.txt with the format:

date:time:client IP address:request.

The client application should:

  • Accept one of the follow commands as command line arguments, and performs the stated task:

    • list, which lists all of the files on the server’s folder serverFiles.
    • get fname, which requests the server send the file fname. This should then be read and saved to the client’s local folder clientFiles.
    • put fname, which sends the file fname from the client’s local folder clientFiles and sends it to the server (to be placed in serverFiles).
  • Quits after completing each command.

The listening port should be 8888. Your solution should work in principle for any files, not just those provided.

The communication protocol between the server and its clients is not specified. You are free to devise any protocol you wish, provided the above requirements are met.

For the purposes of this coursework both the client and the server should run on the same machine, i.e. with hostname localhost. They should not attempt to access each other’s disk space; all communication must be via sockets. UNIX filenames should be used.

Both applications should have basic error handling and your code should adhere to the Java coding standards.